// var i;
// var $item_Bag_EquipItem_UIBindings = require("./Item_Bag_EquipItem_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $const_Hall = require("./Const_Hall");
// var $playerDataManager = require("./PlayerDataManager");
// var $excel = require("./Excel");
// var $bundleConfig = require("./BundleConfig");
// var $commonUtils = require("./CommonUtils");
// var $uIManager = require("./UIManager");
// var $uIConfig_Home = require("./UIConfig_Home");
// var m = cc._decorator;
// var v = m.ccclass;
// var b = m.property;
// var w = m.inspector;
// var I = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.spriteMaterial = [];
//         t.isShowExp = !1;
//         t.miaoBianColor = [
//             new cc.Color(5, 140, 65, 255),
//             new cc.Color(32, 71, 131, 255),
//             new cc.Color(126, 33, 164, 255)
//         ];
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onLoad = function () {
//         this.auto_ui.addClickListener(this._clickListener, this);
//     };
//     t.prototype._clickListener = function (e) {
//         switch (e) {
//             case this.auto_ui.btn_infoBtn:
//                 this.OpenInfo();
//         }
//     };
//     t.prototype.OpenInfo = function (e) {
//         if (void 0 === e) {
//             e = !1;
//         }
//         $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_EquipInfo, {
//             openData: this.openData,
//             upLevelReset: this.ResetThis.bind(this),
//             isAiDressUp: e
//         });
//     };
//     t.prototype.ResetThis = function () {
//         this.StartSet(this.openData);
//     };
//     t.prototype.SetCanClick = function (e) {
//         this.auto_ui.btn_infoBtn.node.active = e;
//     };
//     t.prototype.onEnable = function () {
//         if (this.isShowExp) {
//             this.ResetLevelAndExp();
//         }
//     };
//     t.prototype.StartSet = function (e, t, o) {
//         if (void 0 === t) {
//             t = !0;
//         }
//         if (void 0 === o) {
//             o = !0;
//         }
//         this.SetCanClick(t);
//         this.openData = e;
//         var n = this.auto_ui;
//         this.node.children[0].active = 0 != e.unLockChar;
//         this.node.children[1].active = 0 == e.unLockChar && 0 == e.shuiGuoId;
//         this.node.children[2].active = 0 == e.unLockChar && 0 != e.shuiGuoId;
//         if (0 != e.unLockChar) {
//             n.txt_unLockInfo.string = "通关章节" + e.unLockChar + "解锁";
//         } else {
//             if (0 == e.unLockChar && 0 != e.shuiGuoId) {
//                 var i = $excel.Excel.shuiguo(e.shuiGuoId);
//                 n.txt_nameLabel.string = i.name;
//                 var a = $playerDataManager.PlayerDataMgr.GetEquipDataById(e.shuiGuoId);
//                 var r = a && a.isUnLock;
//                 this.LoadSprite(i.id);
//                 if (o) {
//                     this.SetAllChildIsGray(!r);
//                 } else {
//                     this.SetAllChildIsGray(!1);
//                 }
//                 $excel.Excel.bagEquipRule_all.forEach(function (t) {
//                     if (t.shuiguoId == e.shuiGuoId) {
//                         n.node_geZiFather.children.forEach(function (e) {
//                             e.active = e.name == t.pfbName;
//                         });
//                     }
//                 });
//                 n.node_bgFather.children.forEach(function (e, t) {
//                     e.active = t == i.quality - 1;
//                 });
//                 n.node_tiaoFather.children.forEach(function (e, t) {
//                     e.active = t == i.quality - 1;
//                 });
//                 if (r) {
//                     this.ResetLevelAndExp();
//                 } else {
//                     n.txt_lockLabel.string = "通过章节" + i.unLock + "解锁";
//                     n.txt_levelLabel.string = "";
//                     n.node_bgFather.children[3].active = !0;
//                 }
//                 n.txt_lockLabel.node.active = !r;
//                 n.node_tiaoFather.active = r;
//                 n.node_unLockView.active = r;
//             }
//         }
//     };
//     t.prototype.LoadSprite = function (e) {
//         return __awaiter(this, void 0, void 0, function () {
//             var t = this;
//             return __generator(this, function () {
//                 this._loadRes(
//                     $bundleConfig.BundleNames.Common,
//                     "res/player/player" + (e - 1e3) + "_1",
//                     cc.SpriteFrame
//                 ).then(function (e) {
//                     t.auto_ui.sp_iconSprite.spriteFrame = e;
//                     $commonUtils.default.LimitSpriteMaxSize(t.auto_ui.sp_iconSprite, $const_Hall.equipIconSize);
//                 });
//                 return [2];
//             });
//         });
//     };
//     t.prototype.SetAllChildIsGray = function (e) {
//         var t = this;
//         var o = this.node.children[2].getComponentsInChildren(cc.Sprite);
//         var n = this.node.children[2].getComponentsInChildren(cc.Label);
//         o.forEach(function (o) {
//             if ("4" != o.name) {
//                 o.setMaterial(0, e ? t.spriteMaterial[1] : t.spriteMaterial[0]);
//             }
//         });
//         n.forEach(function (o) {
//             o.setMaterial(0, e ? t.spriteMaterial[1] : t.spriteMaterial[0]);
//         });
//     };
//     t.prototype.ResetLevelAndExp = function () {
//         this.isShowExp = !0;
//         var e = this.openData;
//         var t = this.auto_ui;
//         if (!(e.shuiGuoId < 1e3)) {
//             var o = $playerDataManager.PlayerDataMgr.GetEquipDataById(e.shuiGuoId);
//             t.txt_levelLabel.string = "等级" + o.level;
//             if (o.level > e.upLevelDatas.length) {
//                 t.txt_expLabel.string = o.fragments + "/MAX";
//                 t.progress_expBar.progress = 1;
//                 t.node_expIconFather.children[0].active = !0;
//                 t.node_expIconFather.children[1].stopAllActions();
//                 t.node_expIconFather.children[1].active = !1;
//             } else {
//                 {
//                     var n = e.upLevelDatas[o.level - 1];
//                     t.txt_expLabel.string = o.fragments + "/" + n.shengjixiaohao;
//                     var i = o.fragments / n.shengjixiaohao;
//                     t.progress_expBar.progress = i;
//                     if (t.progress_expBar.progress <= 0) {
//                         t.progress_expBar.progress = 0.05;
//                     }
//                     if (i < 1) {
//                         t.progress_expBar.node.children[0].children[0].opacity = 255;
//                     } else {
//                         t.progress_expBar.node.children[0].children[0].opacity = 0;
//                     }
//                     if (i >= 1) {
//                         t.progress_expBar.node.children[0].children[1].opacity = 255;
//                     } else {
//                         t.progress_expBar.node.children[0].children[1].opacity = 0;
//                     }
//                     t.node_expIconFather.children[0].active = i < 1;
//                     t.node_expIconFather.children[1].active = i >= 1;
//                     if (i >= 1) {
//                         t.node_expIconFather.children[1].stopAllActions();
//                         t.node_expIconFather.children[1].runAction(
//                             cc.repeatForever(cc.sequence(cc.moveTo(0.5, 0, 15), cc.moveTo(0.5, 0, 0)))
//                         );
//                     }
//                 }
//             }
//         }
//     };
//     t.prototype.GetCanUp = function () {
//         var e = $playerDataManager.PlayerDataMgr.GetEquipDataById(this.openData.shuiGuoId);
//         if (e.level <= this.openData.upLevelDatas.length) {
//             var t = this.openData.upLevelDatas[e.level - 1];
//             var o = this.openData.upLevelDatas[e.level - 1];
//             if (e.fragments >= t.shengjixiaohao && $playerDataManager.PlayerDataMgr.globalData.gold >= o.money) {
//                 return !0;
//             }
//         }
//         return !1;
//     };
//     __decorate([b($item_Bag_EquipItem_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     __decorate([b([cc.Material])], t.prototype, "spriteMaterial", void 0);
//     return __decorate([v], t);
// })($resKeeper.default);
// exports.default = I;


// import Item_Bag_EquipItem_UIBindings from './Item_Bag_EquipItem_UIBindings';
// import ResKeeper from './ResKeeper';
// import { PlayerDataMgr } from './PlayerDataManager';
// import { Excel } from './Excel';
// import { BundleNames } from './BundleConfig';
// import CommonUtils from './CommonUtils';
// import UIManager from './UIManager';
// import { UIView_Home } from './UIConfig_Home';
// import { equipIconSize } from './Const_Hall';

// interface OpenData {
//     // 定义 openData 的结构
//     someProperty: string;
//     anotherProperty: number;
// }

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名：EquipItemUI
//  */
// @ccclass
// class Item_Bag_EquipItem extends ResKeeper {
//     @property(Item_Bag_EquipItem_UIBindings)
//     public auto_ui: Item_Bag_EquipItem_UIBindings = null;

//     @property([cc.Material])
//     public spriteMaterial: cc.Material[] = [];

//     public isShowExp: boolean = false;

//     public miaoBianColor: cc.Color[] = [
//         new cc.Color(5, 140, 65, 255),
//         new cc.Color(32, 71, 131, 255),
//         new cc.Color(126, 33, 164, 255)
//     ];

//     public openData:any = null;
    
//     onLoad(): void {
//         this.auto_ui.addClickListener(this._clickListener, this);
//     }

//     /**
//      * 建议方法名：handleClick
//      */
//     private _clickListener(event: cc.Button): void {
//         switch (event) {
//             case this.auto_ui.btn_infoBtn:
//                 this.OpenInfo();
//                 break;
//         }
//     }

//     /**
//      * 建议方法名：openInfo
//      */
//     public OpenInfo(isAiDressUp: boolean = false): void {
//         UIManager.open(BundleNames.Home, UIView_Home.UI_EquipInfo, {
//             openData: this.openData,
//             upLevelReset: this.ResetThis.bind(this),
//             isAiDressUp: isAiDressUp
//         });
//     }

//     /**
//      * 建议方法名：reset
//      */
//     public ResetThis(): void {
//         this.StartSet(this.openData);
//     }

//     /**
//      * 建议方法名：setCanClick
//      */
//     public SetCanClick(canClick: boolean): void {
//         this.auto_ui.btn_infoBtn.node.active = canClick;
//     }

//     onEnable(): void {
//         if (this.isShowExp) {
//             this.ResetLevelAndExp();
//         }
//     }

//     /**
//      * 建议方法名：startSet
//      */
//     public StartSet(openData: any, canClick: boolean = true, setGray: boolean = true): void {
//         this.SetCanClick(canClick);
//         this.openData = openData;
//         const autoUI = this.auto_ui;

//         this.node.children[0].active = openData.unLockChar !== 0;
//         this.node.children[1].active = openData.unLockChar === 0 && openData.shuiGuoId === 0;
//         this.node.children[2].active = openData.unLockChar === 0 && openData.shuiGuoId !== 0;

//         if (openData.unLockChar !== 0) {
//             autoUI.txt_unLockInfo.string = `通关章节${openData.unLockChar}解锁`;
//         } else if (openData.unLockChar === 0 && openData.shuiGuoId !== 0) {
//             const excelData = Excel.shuiguo(openData.shuiGuoId);
//             autoUI.txt_nameLabel.string = excelData.name;
//             const equipData = PlayerDataMgr.GetEquipDataById(openData.shuiGuoId);
//             const isUnlocked = equipData && equipData.isUnLock;

//             this.LoadSprite(excelData.id);

//             if (setGray) {
//                 this.SetAllChildIsGray(!isUnlocked);
//             } else {
//                 this.SetAllChildIsGray(false);
//             }

//             Excel.bagEquipRule_all.forEach((rule: any) => {
//                 if (rule.shuiguoId === openData.shuiGuoId) {
//                     autoUI.node_geZiFather.children.forEach((child: cc.Node) => {
//                         child.active = child.name === rule.pfbName;
//                     });
//                 }
//             });

//             autoUI.node_bgFather.children.forEach((child: cc.Node, index: number) => {
//                 child.active = index === excelData.quality - 1;
//             });

//             autoUI.node_tiaoFather.children.forEach((child: cc.Node, index: number) => {
//                 child.active = index === excelData.quality - 1;
//             });

//             if (isUnlocked) {
//                 this.ResetLevelAndExp();
//             } else {
//                 autoUI.txt_lockLabel.string = `通过章节${excelData.unLock}解锁`;
//                 autoUI.txt_levelLabel.string = '';
//                 autoUI.node_bgFather.children[3].active = true;
//             }

//             autoUI.txt_lockLabel.node.active = !isUnlocked;
//             autoUI.node_tiaoFather.active = isUnlocked;
//             autoUI.node_unLockView.active = isUnlocked;
//         }
//     }

//     /**
//      * 建议方法名：loadSprite
//      */
//     public async LoadSprite(id: number): Promise<void> {
//         const spriteFrame = await this._loadRes(
//             BundleNames.Common,
//             `res/player/player${id - 1000}_1`,
//             cc.SpriteFrame
//         );
//         this.auto_ui.sp_iconSprite.spriteFrame = spriteFrame;
//         CommonUtils.LimitSpriteMaxSize(this.auto_ui.sp_iconSprite, equipIconSize);
//     }

//     /**
//      * 建议方法名：setAllChildGray
//      */
//     public SetAllChildIsGray(isGray: boolean): void {
//         const sprites = this.node.children[2].getComponentsInChildren(cc.Sprite);
//         const labels = this.node.children[2].getComponentsInChildren(cc.Label);

//         sprites.forEach((sprite: cc.Sprite) => {
//             if (sprite.name !== '4') {
//                 sprite.setMaterial(0, isGray ? this.spriteMaterial[1] : this.spriteMaterial[0]);
//             }
//         });

//         labels.forEach((label: cc.Label) => {
//             label.setMaterial(0, isGray ? this.spriteMaterial[1] : this.spriteMaterial[0]);
//         });
//     }

//     /**
//      * 建议方法名：resetLevelAndExp
//      */
//     public ResetLevelAndExp(): void {
//         this.isShowExp = true;
//         const openData = this.openData;
//         const autoUI = this.auto_ui;

//         if (openData.shuiGuoId >= 1000) {
//             const equipData = PlayerDataMgr.GetEquipDataById(openData.shuiGuoId);
//             autoUI.txt_levelLabel.string = `等级${equipData.level}`;

//             if (equipData.level > openData.upLevelDatas.length) {
//                 autoUI.txt_expLabel.string = `${equipData.fragments}/MAX`;
//                 autoUI.progress_expBar.progress = 1;
//                 autoUI.node_expIconFather.children[0].active = true;
//                 autoUI.node_expIconFather.children[1].stopAllActions();
//                 autoUI.node_expIconFather.children[1].active = false;
//             } else {
//                 const levelData = openData.upLevelDatas[equipData.level - 1];
//                 autoUI.txt_expLabel.string = `${equipData.fragments}/${levelData.shengjixiaohao}`;
//                 const progress = equipData.fragments / levelData.shengjixiaohao;
//                 autoUI.progress_expBar.progress = progress;

//                 if (autoUI.progress_expBar.progress <= 0) {
//                     autoUI.progress_expBar.progress = 0.05;
//                 }

//                 autoUI.progress_expBar.node.children[0].children[0].opacity = progress < 1 ? 255 : 0;
//                 autoUI.progress_expBar.node.children[0].children[1].opacity = progress >= 1 ? 255 : 0;

//                 autoUI.node_expIconFather.children[0].active = progress < 1;
//                 autoUI.node_expIconFather.children[1].active = progress >= 1;

//                 if (progress >= 1) {
//                     autoUI.node_expIconFather.children[1].stopAllActions();
//                     autoUI.node_expIconFather.children[1].runAction(
//                         cc.repeatForever(cc.sequence(cc.moveTo(0.5, 0, 15), cc.moveTo(0.5, 0, 0)))
//                     );
//                 }
//             }
//         }
//     }

//     /**
//      * 建议方法名：canUpgrade
//      */
//     public GetCanUp(): boolean {
//         const equipData = PlayerDataMgr.GetEquipDataById(this.openData.shuiGuoId);

//         if (equipData.level <= this.openData.upLevelDatas.length) {
//             const levelData = this.openData.upLevelDatas[equipData.level - 1];
//             const nextLevelData = this.openData.upLevelDatas[equipData.level - 1];

//             if (equipData.fragments >= levelData.shengjixiaohao && PlayerDataMgr.globalData.gold >= nextLevelData.money) {
//                 return true;
//             }
//         }

//         return false;
//     }
// }

// export default Item_Bag_EquipItem;

import BagEquipItemUIBindings from './Item_Bag_EquipItem_UIBindings';
import ResKeeper from './ResKeeper';
import { PlayerDataMgr } from './PlayerDataManager';
import { Excel } from './Excel';
import { BundleNames } from './BundleConfig';
import CommonUtils from './CommonUtils';
import UIManager from './UIManager';
import { UIView_Home } from './UIConfig_Home';
import { equipIconSize } from './Const_Hall';

interface OpenData {
    someProperty: string;
    anotherProperty: number;
}

const { ccclass, property, inspector } = cc._decorator;

/** 
 * @建议类名：EquipItemUI  
*/
@ccclass
class ItemBagEquipItem extends ResKeeper {
    @property(BagEquipItemUIBindings)
    public auto_ui: BagEquipItemUIBindings = null;

    @property([cc.Material])
    public spriteMaterial: cc.Material[] = [];

    public isShowExp: boolean = false;

    public miaoBianColor: cc.Color[] = [
        new cc.Color(5, 140, 65, 255),
        new cc.Color(32, 71, 131, 255),
        new cc.Color(126, 33, 164, 255)
    ];

    public openData: any = null;

    onLoad(): void {
        this.auto_ui.addClickListener(this._clickListener, this);
    }

    /** 
     * @建议方法名：handleClick  
    */
    private _clickListener(buttonEvent: cc.Button): void {
        if (buttonEvent === this.auto_ui.btn_infoBtn) {
            this.openInfo();
        }
    }

    /** 
     * @建议方法名：openInfo  
    */
    public openInfo(isAiDressUp: boolean = false): void {
        UIManager.open(BundleNames.Home, UIView_Home.UI_EquipInfo, {
            openData: this.openData,
            upLevelReset: this.reset.bind(this),
            isAiDressUp: isAiDressUp
        });
    }

    /** 
     * @建议方法名：reset  
    */
    public reset(): void {
        this.startSet(this.openData);
    }

    /** 
     * @建议方法名：setCanClick  
    */
    public setCanClick(canClick: boolean): void {
        this.auto_ui.btn_infoBtn.node.active = canClick;
    }

    onEnable(): void {
        if (this.isShowExp) {
            this.resetLevelAndExp();
        }
    }

    /**
     * @建议方法名：startSet
     * @param openData - 传入的开数据对象
     * @param canClick - 是否可点击
     * @param setGray - 是否设置为灰色
     */
    public startSet(openData: any, canClick: boolean = true, setGray: boolean = true): void {
        this.setCanClick(canClick);
        this.openData = openData;

        const autoUIBindings = this.auto_ui;

        this.node.children[0].active = openData.unLockChar !== 0;
        this.node.children[1].active = openData.unLockChar === 0 && openData.shuiGuoId === 0;
        this.node.children[2].active = openData.unLockChar === 0 && openData.shuiGuoId !== 0;

        if (openData.unLockChar !== 0) {
            autoUIBindings.txt_unLockInfo.string = `通关章节${openData.unLockChar}解锁`;
        } else if (openData.unLockChar === 0 && openData.shuiGuoId !== 0) {
            const shuiguoData = Excel.shuiguo(openData.shuiGuoId);
            const equipData = PlayerDataMgr.getEquipDataById(openData.shuiGuoId);
            const isUnlocked = !!equipData?.isUnLock;

            autoUIBindings.txt_nameLabel.string = shuiguoData.name;

            this.loadSprite(shuiguoData.id);
            this.setAllChildGray(setGray ? !isUnlocked : false);

            this.updateBagEquipRule(shuiguoData.id);
            this.updateQualityDisplay(shuiguoData.quality);
            
            this.updateLevelAndExpDisplay(isUnlocked, shuiguoData.unLock);

            autoUIBindings.txt_lockLabel.node.active = !isUnlocked;
            autoUIBindings.node_tiaoFather.active = isUnlocked;
            autoUIBindings.node_unLockView.active = isUnlocked;
        }
    }

    /**
     * @建议方法名：updateBagEquipRule
     * 更新背包装备规则显示
     * @param shuiGuoId - 水果ID
     */
    private updateBagEquipRule(shuiGuoId: number): void {
        const autoUIBindings = this.auto_ui;
        Excel.bagEquipRule_all.forEach((rule: any) => {
            if (rule.shuiguoId === shuiGuoId) {
                autoUIBindings.node_geZiFather.children.forEach((child: cc.Node) => {
                    child.active = (child.name === rule.pfbName);
                });
            }
        });
    }

    /**
     * @建议方法名：updateQualityDisplay
     * 更新品质显示
     * @param quality - 品质等级
     */
    private updateQualityDisplay(quality: number): void {
        const autoUIBindings = this.auto_ui;
        autoUIBindings.node_bgFather.children.forEach((child: cc.Node, index: number) => {
            child.active = index === quality - 1;
        });

        autoUIBindings.node_tiaoFather.children.forEach((child: cc.Node, index: number) => {
            child.active = index === quality - 1;
        });
    }

    /**
     * @建议方法名：updateLevelAndExpDisplay
     * 更新等级和经验显示
     * @param isUnlocked - 是否已解锁
     * @param unLock - 解锁字符
     */
    private updateLevelAndExpDisplay(isUnlocked: boolean, unLock: string): void {
        const autoUIBindings = this.auto_ui;
        if (isUnlocked) {
            this.resetLevelAndExp();
        } else {
            autoUIBindings.txt_lockLabel.string = `通过章节${unLock}解锁`;
            autoUIBindings.txt_levelLabel.string = '';
            autoUIBindings.node_bgFather.children[3].active = true;
        }
    }

    /** 
     * @建议方法名：loadSprite  
    */
    public async loadSprite(equipId: number): Promise<void> {
        const spritePath = `res/player/player${equipId - 1000}_1`;
        const spriteFrame = await this._loadRes(BundleNames.Common, spritePath, cc.SpriteFrame);
        const iconSprite = this.auto_ui.sp_iconSprite;

        iconSprite.spriteFrame = spriteFrame;
        CommonUtils.limitSpriteSize(iconSprite, equipIconSize);
    }

    /** 
     * @建议方法名：setAllChildGray  
    */
    public setAllChildGray(isGray: boolean): void {
        const childrenSprites = this.node.children[2].getComponentsInChildren(cc.Sprite);
        const childrenLabels = this.node.children[2].getComponentsInChildren(cc.Label);

        childrenSprites.forEach((sprite: cc.Sprite) => {
            if (sprite.name !== '4') {
                sprite.setMaterial(0, isGray ? this.spriteMaterial[1] : this.spriteMaterial[0]);
            }
        });

        childrenLabels.forEach((label: cc.Label) => {
            label.setMaterial(0, isGray ? this.spriteMaterial[1] : this.spriteMaterial[0]);
        });
    }

    /** 
     * @建议方法名：resetLevelAndExp  
    */
    public resetLevelAndExp(): void {
        this.isShowExp = true;
        const openData = this.openData;
        const equipData = PlayerDataMgr.getEquipDataById(openData.shuiGuoId);
        const autoUIBindings = this.auto_ui;

        if (openData.shuiGuoId >= 1000 && equipData) {
            this.updateLevelDisplay(equipData.level);
            this.updateExpDisplay(equipData, openData.upLevelDatas[equipData.level - 1]);
        }
    }

    /**
     * @建议方法名：updateLevelDisplay
     * 更新等级显示
     * @param level - 装备等级
     */
    private updateLevelDisplay(level: number): void {
        this.auto_ui.txt_levelLabel.string = `等级${level}`;
    }

    /**
     * @建议方法名：updateExpDisplay
     * 更新经验显示
     * @param equipData - 装备数据
     * @param levelData - 等级数据
     */
    private updateExpDisplay(equipData: any, levelData: any): void {
        const autoUIBindings = this.auto_ui;
        if (equipData.level > this.openData.upLevelDatas.length) {
            this.maxExperienceReached(equipData.fragments);
        } else {
            this.updateProgressBar(equipData.fragments, levelData.shengjixiaohao);
        }
    }

    /**
     * @建议方法名：maxExperienceReached
     * 最大经验显示
     * @param fragments - 装备碎片
     */
    private maxExperienceReached(fragments: number): void {
        const autoUIBindings = this.auto_ui;

        autoUIBindings.txt_expLabel.string = `${fragments}/MAX`;
        autoUIBindings.progress_expBar.progress = 1;
        autoUIBindings.node_expIconFather.children[0].active = true;
        autoUIBindings.node_expIconFather.children[1].stopAllActions();
        autoUIBindings.node_expIconFather.children[1].active = false;
    }

    /** 
     * @建议方法名：updateProgressBar
     * 更新进度条显示
     * @param fragments - 当前碎片
     * @param upgradeCost - 升级碎片需求
     */
    private updateProgressBar(fragments: number, upgradeCost: number): void {
        const autoUIBindings = this.auto_ui;
        const progress = fragments / upgradeCost;

        autoUIBindings.txt_expLabel.string = `${fragments}/${upgradeCost}`;
        autoUIBindings.progress_expBar.progress = progress;

        autoUIBindings.progress_expBar.progress = Math.max(autoUIBindings.progress_expBar.progress, 0.05);

        autoUIBindings.progress_expBar.node.children[0].children[0].opacity = progress < 1 ? 255 : 0;
        autoUIBindings.progress_expBar.node.children[0].children[1].opacity = progress >= 1 ? 255 : 0;

        autoUIBindings.node_expIconFather.children[0].active = progress < 1;
        autoUIBindings.node_expIconFather.children[1].active = progress >= 1;

        if (progress >= 1) {
            this.addFullExpAnimation();
        }
    }

    /** 
     * @建议方法名：addFullExpAnimation
     * 加满经验值动画
     */
    private addFullExpAnimation(): void {
        const autoUIBindings = this.auto_ui;
        autoUIBindings.node_expIconFather.children[1].stopAllActions();
        autoUIBindings.node_expIconFather.children[1].runAction(
            cc.repeatForever(cc.sequence(cc.moveTo(0.5, 0, 15), cc.moveTo(0.5, 0, 0)))
        );
    }

    /** 
     * @建议方法名：canUpgrade  
    */
    public canUpgrade(): boolean {
        const equipData = PlayerDataMgr.getEquipDataById(this.openData.shuiGuoId);

        if (equipData.level <= this.openData.upLevelDatas.length) {
            const levelData = this.openData.upLevelDatas[equipData.level - 1];
            const nextLevelData = this.openData.upLevelDatas[equipData.level - 1];

            if (equipData.fragments >= levelData.shengjixiaohao && PlayerDataMgr.globalData.gold >= nextLevelData.money) {
                return true;
            }
        }

        return false;
    }
}

export default ItemBagEquipItem;